<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>地形加载</title>
    <link href="../Build/Cesium/Widgets/widgets.css" rel="stylesheet" />
    <script src="../Build/Cesium/Cesium.js"></script>
    <script src="plugin/sensor.js"></script>
    <style>
        html,
        body,
        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
    </style>

</head>

<body>
    <div id="cesiumContainer"></div>
    <script>
     let osm = new Cesium.UrlTemplateImageryProvider({
         url: "http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali"
     });

		// let osm = Cesium.createOpenStreetMapImageryProvider({
        //     url: 'https://a.tile.openstreetmap.org/'
        // });
        let terrain = new Cesium.CesiumTerrainProvider({
            url: "../Source/Terrain/beijing/"
        });
        let viewer = new Cesium.Viewer('cesiumContainer', {
            imageryProvider: osm,
            terrainProvider: terrain,//地形数据源
            contextOptions: {
                webgl: {
                    alpha: true
                }
            },
            selectionIndicator: false,
            animation: false,  //是否显示动画控件
            baseLayerPicker: false, //是否显示图层选择控件
            geocoder: false, //是否显示地名查找控件
            timeline: false, //是否显示时间线控件
            sceneModePicker: false, //是否显示投影方式控件
            navigationHelpButton: false, //是否显示帮助信息控件
            infoBox: false,  //是否显示点击要素之后显示的信息
            fullscreenButton: false,
            shouldAnimate: true //动画播放
        });

        //取消双击事件
        //viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
        //设置homebutton的位置
        Cesium.Camera.DEFAULT_VIEW_RECTANGLE =
            Cesium.Rectangle.fromDegrees(116.15, 40.54, 116.25, 40.56);//Rectangle(west, south, east, north)
        //设置初始位置
        viewer.camera.setView({
            destination: Cesium.Cartesian3.fromDegrees(116.20, 40.55, 3000000)
        });

        //开启深度检测
        //viewer.scene.globe.depthTestAgainstTerrain = true;
		
		let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
            Cesium.Cartesian3.fromDegrees(116.39,39.91, 0.0));

        viewer.scene.primitives.add(Cesium.Model.fromGltf({
            url: '../Apps/SampleData/models/GroundVehicle/GroundVehicle.glb',
            modelMatrix: modelMatrix,
            scale: 10.0
        }));
        
        
		//飞机
        viewer.entities.add({
            name: "飞机",
            position: Cesium.Cartesian3.fromDegrees(116.39,39.91, 2000),
            orientation: Cesium.Transforms.headingPitchRollQuaternion(Cesium.Cartesian3.fromDegrees(116.39,39.91, 3000), new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(0), 0, 0)),//和飞行姿态相关
            model: {
                uri: "../Apps/SampleData/models/CesiumAir/Cesium_Air.glb",
                minimumPixelSize: 128,
                maximumScale: 20000
            }
        });
        
        viewer.entities.add({
            position: Cesium.Cartesian3.fromDegrees(116.39,39.91, 0.0),
            name: '绿色圆',
            ellipse: {
                semiMinorAxis: 10000.0,
                semiMajorAxis: 10000.0,
                height: 0.0,
                material: new Cesium.Color(0, 1, 1, .4)
            }
        });
        
//      let r = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(90),
//          Cesium.Math.toRadians(0),
//          Cesium.Math.toRadians(0));
//      let l = Cesium.Cartesian3.fromDegrees(116.39,39.91, 128);
//      let sensorEntity = viewer.entities.add({
//          position: l,
//          orientation: Cesium.Transforms.headingPitchRollQuaternion(l, r),
//          rectangularSensor: new Cesium.RectangularSensorGraphics({
//              radius: 1000,
//              xHalfAngle: Cesium.Math.toRadians(90),
//              yHalfAngle: Cesium.Math.toRadians(90),
//              material: new Cesium.Color(0, 1, 1, .4),
//              lineColor: new Cesium.Color(0, 1, 1, 1),
//              showScanPlane: true,
//              scanPlaneColor: new Cesium.Color(0, 1, 1, 1),
//              scanPlaneMode: "vertical",
//              scanPlaneRate: 3,
//              showThroughEllipsoid: !1
//          })
//      })
    </script>
</body>

</html>